<?php

namespace app\admin\controller;

use think\Controller;
use think\facade\Request;
use app\admin\model\Goods as goodslist;
use think\Db;

class Test extends Controller
{
    public function index(){
        return $this->fetch();
    }

    public function test(){
        // $data=db('goods')->select();
        // return $this->fetch('test',['data'=>$data]);
        // 通过模型
        //查询列表数据
        $data=goodslist::select();
        return $this->fetch('test',['data'=>$data]);
    }

    public function read($id){
        $data=goodslist::find($id);
        return $this->fetch('read',['data'=>$data]);
        // dump($data);
    }
    public function add(){
        return $this->fetch();
    }

    public function getadd(){
        $data=Request::param();
        goodslist::create($data,true);
        // $this->success('添加成功','test');
        return $this->redirect('test');
    }

    public function search(){
        $name=Request::param('name');
        $data=goodslist::where('goods_name','like',"%$name%")->select();
        return $this->fetch('test',['data'=>$data]);
    }

    public function del(){
        $id=Request::param('id');
        goodslist::where('id',$id)->delete();
        return $this->redirect('test');
    }

    public function edit(){
        $id=Request::param('id');
        $data=goodslist::where('id',$id)->find();
        return $this->fetch('edit',['data'=>$data]);
    }
    
    public function getedit(){
        $id=Request::param('id');
        $data=Request::param();
        goodslist::where('id',$id)->update($data,true);
        return $this->redirect('test');
    }

}
